<template>
  <!-- <div>住户信息展示</div> -->
  <div class="container">
    <el-table
      :data="
        tableData.listdata.slice(
          (currentPage4 - 1) * pageSize4,
          currentPage4 * pageSize4
        )
      "
      stripe
      style="width: 100%"
    >
      <el-table-column prop="id" label="编号" />
      <el-table-column prop="number" label="门牌号" />
      <el-table-column prop="name" label="户主姓名" />
      <el-table-column prop="address" label="住址" />
      <el-table-column prop="type" label="房屋用途" />
      <el-table-column prop="typeHome" label="户型" />
      <el-table-column>
        <template #header>
          <el-input
            v-model="search"
            size="small"
            placeholder="请输入查询内容"
            @blur="handleSearch"
          />
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <div class="bottom">
      <el-pagination
        v-model:current-page="currentPage4"
        v-model:page-size="pageSize4"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.listdata.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, reactive } from "vue";
import link from "@/api/link.js";
import apiUrl from "@/api/url.js";

let search = ref("");

const currentPage4 = ref(1);
const pageSize4 = ref(10);
const small = ref(false);
const background = ref(false);
const disabled = ref(false);

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  pageSize4.value = val;
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  currentPage4.value = val;
};

let tableData = reactive({
  listdata: [],
});

let handleSearch = () => {
  link(apiUrl.userlist, "GET", {}, { name: search.value }).then(
    (resolve: any) => {
      console.log(resolve);
      tableData.listdata = resolve.data;
    }
  );
};

onMounted(() => {
  link(apiUrl.userlist).then((resolve: any) => {
    console.log(resolve);
    tableData.listdata = resolve.data;
  });
});
</script>

<style scoped lang="scss">
.container {
  width: 98%;
  margin: 20px auto;
  .bottom {
    margin: 5px;
    .el-pagination {
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
